package net.zeus.rabbitmq.controller;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import net.zeus.rabbitmq.config.RabbitConfig;

@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private AmqpTemplate rabbitTemplate;
	
	@Autowired
	private RabbitConfig rabbitConfig;
	
	@PostMapping("/add")
	public String userAdd(@RequestBody String userName) {
		System.out.println("controller --");
		rabbitTemplate.convertAndSend(rabbitConfig.getExchange(), rabbitConfig.getKeyInfo(), "hello " + userName);
		return "send name" + userName;
	}
}
